void	my_putchar(char c)
{
  write(1, &c, 1);
}

int	my_strlen(char *str)
{
  int	i;

  i = 0;
  while(str[i])
    i++;
  return (i);
}

int	my_getnbr(char *str)
{
  int   i;
  int   res;
  int   minus;

  i = 0;
  res = 0;
  minus = 0;
  while ((str[i] == '+') || (str[i] == '-'))
    {
      minus++;
      i++;
    }
  while ((str[i] >= '0') && (str[i] <= '9') && (str[i] != '\0'))
    {
      res = res * 10;
      res = res + str[i] - '0';
      i++;
    }
  if (minus % 2)
    res = -res;
  return (res);
}

void    my_putnbr_base(int nbr, char *base)
{
  int   tmp;
  int   div;
  int   b;
  int   p;

  p = 0;
  b = my_strlen(base);
  p = 1;
  div = 1;
  if (nbr < 0)
    {
      nbr *= -1;
      my_putchar('-');
    }
  while (nbr / p > b - 1)
    p = p * b;
  tmp = 0;
  while (p >= 1)
    {
      tmp = (tmp * 10) + (base[nbr / p]-'0');
      nbr = nbr % p;
      p = p / b;
      my_putchar(tmp + '0');
      tmp = 0;
    }
}

int	main(int ac, char **av)
{
  int	nb;

  if (ac == 3)
    {
      nb = my_getnbr(av[1]);
      my_putnbr_base(nb, av[2]);
    }
  my_putchar('\n');
}
